package com.liukai.novel_commons.db;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

public class DBHelper extends SQLiteOpenHelper {

    public static final String CREATE_USER = "create table user(" +
            "user_id varchar(20)," + // 用户账号
            "user_name varchar(50)," + // 用户名
            "user_pass varchar(20)," + // 密码
            "role_id int(3)," + // 权限id
            "user_img varchar(200)," + // 用户头像
            "read_time int(10)" + // 阅读时长
            ")";

    public static final String CREATE_RACK = "create table rack(" +
            "user_id varchar(20)," +
            "novel_id long," +
            "recently_read int(8)," +
            "is_update int(2)," +
            "add_time long," +
            "read_time long)";

    public DBHelper(Context context){
        super(context,"novel.db",null,1);
    }

    public DBHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public DBHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version, @Nullable DatabaseErrorHandler errorHandler) {
        super(context, name, factory, version, errorHandler);
    }

    @RequiresApi(api = Build.VERSION_CODES.P)
    public DBHelper(@Nullable Context context, @Nullable String name, int version, @NonNull SQLiteDatabase.OpenParams openParams) {
        super(context, name, version, openParams);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(CREATE_USER);
        db.execSQL(CREATE_RACK);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
